# -*- coding:utf-8 -*-

class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        if s is None:
            return
        res = ""
        for i in range(len(s)):
            tmp = self.find(s, i, i)
            if len(tmp) > len(res):
                res = tmp

            tmp = self.find(s, i, i + 1)
            if len(tmp) > len(res):
                res = tmp
        return res

    def find(self, s, left, right):
        while  left >= 0 and right < len(s) and s[left] == s[right]:
            left -= 1
            right += 1
        return s[left+1:right]


if __name__ == "__main__":
    print Solution().longestPalindrome("abab")
